import {Spin} from "antd";
import React, {FC, useCallback, useEffect, useMemo} from "react";
import {useNavigate} from "react-router";
import {AxiosGet} from "../services/HttpService.tsx";

interface RedirectProps {
}

const Redirect: FC<RedirectProps> = (props) => {
    const navigate = useNavigate();

    const init = useCallback(async () => {
        const {data} = await AxiosGet("/sf-drs/platform/oauth/url")
        window.location.href = data.loginUrl;
    }, [])

    useEffect(() => {
        init()
    }, [navigate]);

    const renderRedirect = useMemo(() => {
        return (
            <Spin tip="Loading...">
                <div style={{height: "100vh", lineHeight: "100vh", textAlign: "center"}}>
                </div>
            </Spin>
        )
    }, [props]);

    return (renderRedirect);
};

export default React.memo(Redirect);